home *** CD-ROM | disk | FTP | other *** search
- /************************************************************************************************/
- /* */
- /* Program Name: Stiletto */
- /* */
- /* File Name: LogWindow.c */
- /* */
- /* © Apple Computer, Inc. 1991-1995 */
- /* All Rights Reserved */
- /* */
- /* Revision History: */
- /* */
- /* Date Who Modification */
- /* */
- /* 1991-06-11 Chris Halim Original version */
- /* 1995-06-26 Jaakko Railo Version 2.0 */
- /* */
- /************************************************************************************************/
-
- /****************************************** DESCRIPTION ******************************************
-
- *************************************************************************************************/
-
- /******************************************** HEADERS *******************************************/
-
- #include "Resources.h"
- #include "StandardFile.h"
- #include "stdarg.h"
- #include "stdio.h"
- #include "string.h"
- #include "Strings.h"
- #include "ToolUtils.h"
-
- #include "flstUtilities.h"
- #include "LogWindow.h"
- #include "Utilities.h" // we use AlertUser()
-
- /****************************************** DEFINITIONS *****************************************/
-
- #define kTopMargin 21
- #define kTextMargin 2
- #define kStrBufferSize 512
-
- #if defined(powerc) || defined (__powerc)
- #pragma options align=mac68k
- #endif
- struct LWINRec {
- short numOfLines;
- short maxWidth;
- short minWidth;
- };
- #if defined(powerc) || defined(__powerc)
- #pragma options align=reset
- #endif
-
- typedef struct LWINRec LWINRec;
-
- typedef LWINRec *LWINRecPtr, **LWINRecHandle;
-
- /****************************************** PROTOTYPES ******************************************/
-
- void DrawLogWindow (WindowPtr theWindow);
- void DoLogWindowActivate (WindowPtr theWindow, Boolean becomingActive);
- void DoLogWindowUpdate (WindowPtr theWindow);
- void DoLogWindowOSEvent (const EventRecord *theEvent);
- void DoLogWindowSuspend (Boolean doClipConvert);
- void DoLogWindowResume (Boolean doClipConvert);
- Boolean DoLogWindowMouseDown (const EventRecord *theEvent);
- void DoLogWindowClick (WindowPtr theWindow, const EventRecord * theEvent);
- void DoLogWindowGrow (WindowPtr theWindow, const EventRecord * theEvent);
- void DoLogWindowZoom (WindowPtr theWindow, short part);
-
- void TELiteScroll (LogWindowPtr logWindow, short value);
-
- TELiteHandle CreateNewTELite (Boolean colorPort);
- void GetTERect (WindowPtr theWindow, Rect * theRect);
- void AdjustHV (Boolean isVert, ControlHandle control, TELiteHandle theTELite, Boolean canRedraw);
- void AdjustScrollValues (LogWindowPtr logWindow, Boolean canRedraw);
- void AdjustScrollSizes (LogWindowPtr logWindow);
- void AdjustScrollbars (LogWindowPtr logWindow,Boolean needsResize);
- void ShowGrowIcon (WindowPtr theWindow);
- void AdjustHeight (short * height, LogWindowPtr logWindow);
-
- void CommonAction (ControlHandle theControl, short * amount);
- void DrawFromOffscreen (LogWindowPtr logWindow);
-
- Boolean FillFSSpec (LogWindowPtr logWindow);
- void AppendLine (LogWindowPtr logWindow, const char * cStr);
-
- void PutTextToLogWindow (LogWindowPtr logWindow, const char * cStr);
-
- /******************************************** GLOBALS *******************************************/
-
- extern ControlActionUPP gVActionProcUPP;
-
- /************************************************************************************************/
- /************************************************************************************************/
-
-
- #pragma segment LogWindowSeg
- short CreateLogWindow (LogWindowPtr * logWindow, const Rect * windowRect)
- {
- WindowPtr savedPort;
- Ptr tPtr;
- Rect boundsRect;
- short height;
- RgnHandle grayRgn;
-
- /**
- ** Create storage for the window record. We will pass this to GetNewWindow().
- **
- **/
-
- tPtr = NewPtr (sizeof (LogWindowRec));
- if (tPtr == nil) {
- AlertUser ("\pNot enough memory to create log window !", MemError ());
- return (-1);
- }
-
- /**
- ** Get a "WIND" resource for the log window.
- **
- **/
-
- if (HasColorQD())
- *logWindow = (LogWindowPtr) GetNewCWindow (rLogWIND, tPtr, (WindowPtr)(-1L));
- else
- *logWindow = (LogWindowPtr) GetNewWindow (rLogWIND, tPtr, (WindowPtr)(-1L));
-
- if (*logWindow == nil) {
- AlertUser ("\pUnable to get a WIND resource for log window!", ResError ());
- DisposPtr (tPtr);
- return (-1);
- }
-
- /**
- ** Move and resize the window according to the rect passed in windowRect.
- ** Also make sure that the window is within the screen boundary.
- **
- **/
-
- grayRgn = GetGrayRgn ();
- if (windowRect && !EmptyRect(windowRect) && RectInRgn (windowRect, grayRgn)) {
- MoveWindow ((WindowPtr) *logWindow, windowRect->left, windowRect->top, false);
- height = windowRect->bottom - windowRect->top;
- SizeWindow ((WindowPtr) *logWindow, windowRect->right - windowRect->left,
- height, true);
- }
-
- /**
- ** Set the window's characteristics.
- **
- **/
-
- GetPort (&savedPort);
- SetPort ((WindowPtr) *logWindow);
- TextSize (9);
- SetPort (savedPort);
-
- /**
- ** Create a new vertical control scroll.
- **
- **/
-
- boundsRect = ((WindowPtr) tPtr)->portRect;
- boundsRect.top += kTopMargin - 1;
- ++boundsRect.right;
- boundsRect.bottom -= 14;
- boundsRect.left = boundsRect.right - 16;
- ((LogWindowPtr) tPtr)->vScroll = NewControl ((WindowPtr) tPtr, &boundsRect,
- "\pvScroll", true, 0, 0, 0, scrollBarProc, 0);
-
- /**
- ** Get checkBox & button from resource.
- **
- **/
-
- ((LogWindowPtr) tPtr)->saveCheckBox = GetNewControl (rSaveCheckBoxCNTL,(WindowPtr) tPtr);
- ((LogWindowPtr) tPtr)->clearLogButton = GetNewControl (rClearLogButtonCNTL,(WindowPtr) tPtr);
-
- /**
- ** Create a TELiteHandle for the the log window.
- **
- **/
-
- if (((*logWindow)->fTELiteHandle = CreateNewTELite (false)) == nil)
- return (-1);
-
- (*(LogWindowPtr) tPtr).logFileSpec = nil;
- (*(LogWindowPtr) tPtr).saveToDisk = false;
-
- ShowWindow ((WindowPtr) *logWindow);
-
- return (noErr);
- }
-
-
- #pragma segment LogWindowSeg
- Boolean IsHandledByLogWindow (LogWindowPtr logWindow, const EventRecord * theEvent)
- {
- WindowPtr theWindow;
- Boolean wasHandled = false;
-
- if (logWindow != nil) {
- switch ( theEvent->what ) {
- case mouseDown:
- (void) FindWindow(theEvent->where, &theWindow);
- if (theWindow == (WindowPtr) logWindow) {
- wasHandled = DoLogWindowMouseDown (theEvent);
- }
- break;
-
- case activateEvt:
- if ((LogWindowPtr) theEvent->message == logWindow) {
- DoLogWindowActivate ((WindowPtr) logWindow, (theEvent->modifiers & activeFlag) != 0);
- wasHandled = true;
- }
- break;
-
- case updateEvt:
- if ((LogWindowPtr) theEvent->message == logWindow) {
- DoLogWindowUpdate ((WindowPtr) logWindow);
- wasHandled = true;
- }
- break;
-
- case osEvt:
- if ((LogWindowPtr) FrontWindow () == logWindow) {
- DoLogWindowOSEvent (theEvent);
- wasHandled = false; // we want main program to still handle osevt
- // it may want to convert scrap etc.
- }
- break;
- }
- }
-
- return (wasHandled);
- }
-
-
- #pragma segment LogWindowSeg
- void DoLogWindowOSEvent (const EventRecord *theEvent)
- {
- Boolean doConvert;
- unsigned char evType;
-
- evType = (unsigned char) (theEvent->message >> 24) & 0x00ff; // Get the high byte.
- switch (evType) { // The high byte of message is the type of event.
- case suspendResumeMessage :
- doConvert = (theEvent->message & convertClipboardFlag) != 0;
-
- if ((theEvent->message & resumeFlag) == 0)
- DoLogWindowSuspend (doConvert);
-
- else DoLogWindowResume (doConvert);
- break;
- }
- }
-
-
- #pragma segment LogWindowSeg
- void DoLogWindowSuspend (Boolean doClipConvert)
- {
- #pragma unused (doClipConvert)
-
- DoLogWindowActivate (FrontWindow(), false);
- }
-
-
- #pragma segment LogWindowSeg
- void DoLogWindowResume (Boolean doClipConvert)
- {
- #pragma unused (doClipConvert)
-
- InitCursor ();
- DoLogWindowActivate (FrontWindow(), true);
- }
-
-
- #pragma segment LogWindowSeg
- Boolean DoLogWindowMouseDown (const EventRecord *theEvent)
- {
- short part;
- WindowPtr theWindow;
- Boolean wasHandled = false;
-
- part = FindWindow(theEvent->where, &theWindow);
- switch ( part ) {
- case inContent:
- if ( theWindow != FrontWindow() ) {
- SelectWindow(theWindow);
- } else
- DoLogWindowClick (theWindow, theEvent);
-
- wasHandled = true;
- break;
-
- case inDrag: // pass screenBits.bounds to get all gDevices
- if (!(theEvent->modifiers & cmdKey)) // if command key isn't down
- SelectWindow (theWindow);
-
- DragWindow (theWindow, theEvent->where, &qd.screenBits.bounds);
-
- wasHandled = true;
- break;
-
- case inGoAway:
- if ( TrackGoAway (theWindow, theEvent->where) )
- HideWindow (theWindow);
- wasHandled = true;
- break;
-
- case inGrow:
- DoLogWindowGrow (theWindow, theEvent);
- wasHandled = true;
- break;
-
- case inZoomIn:
- case inZoomOut:
- if ( TrackBox (theWindow, theEvent->where, part) )
- DoLogWindowZoom (theWindow, part);
-
- wasHandled = true;
- break;
- }
-
- return (wasHandled);
- }
-
-
- #pragma segment LogWindowSeg
- TELiteHandle CreateNewTELite (Boolean colorPort)
- {
- GrafPtr savedPort, tPort;
- BitMap *tBitMapPtr;
- short rowBytes, width, height, lineHeight;
- TELiteHandle theTELite;
- TextState textInfo;
- FontInfo tPortFontInfo;
- LWINRecHandle lwinResource;
-
- lwinResource = (LWINRecHandle) Get1Resource ('LWIN', rLogLWIN);
- if (lwinResource == nil) {
- AlertUser ("\pUnable to retrieve the needed resource", MemError ());
- return (nil);
- }
-
- /**
- ** Create the offscreen port.
- **
- **/
-
- if (colorPort)
- tPort = (GrafPtr) NewPtr (sizeof (CGrafPort));
- else
- tPort = (GrafPtr) NewPtr (sizeof (GrafPort));
-
- if (tPort == nil) {
- AlertUser ("\pCan't allocate memory for our offscreen port", MemError ());
- ReleaseResource ((Handle) lwinResource);
- return (nil);
- }
-
- GetPort (&savedPort);
-
- if (colorPort)
- OpenCPort ((CGrafPtr) tPort);
- else
- OpenPort (tPort);
-
- SetPort (tPort);
-
- GetIndflst (rLogWindowflst, 1, &textInfo);
- TextFont (textInfo.theFont);
- TextFace (textInfo.theFace);
- TextSize (textInfo.theSize);
- TextMode (textInfo.theMode);
-
- GetFontInfo (&tPortFontInfo);
- lineHeight = tPortFontInfo.ascent + tPortFontInfo.descent + tPortFontInfo.leading;
-
- /**
- ** Create the bitmap to be used by our offscreen port.
- **
- **/
-
- width = (*lwinResource)->maxWidth;
- height = lineHeight * (*lwinResource)->numOfLines; // maxLines * lineHeight;
-
- rowBytes = ((width + 15) / 16) * 2;
- tBitMapPtr = (BitMap*) NewPtrClear ((long) rowBytes * height + sizeof (BitMap));
- if (tBitMapPtr == nil) {
- AlertUser ("\pCan't allocate memory for our offscreen BitMap", MemError ());
- DisposPtr ((Ptr) tPort);
- ReleaseResource ((Handle) lwinResource);
- return (nil);
- }
-
- tBitMapPtr->rowBytes = rowBytes;
- tBitMapPtr->baseAddr = (Ptr) (tBitMapPtr + 1);
- SetRect(&tBitMapPtr->bounds, 0, 0, width, height);
-
- SetPortBits (tBitMapPtr);
- PortSize (width, height);
- SetOrigin (0, 0);
- ClipRect (&tBitMapPtr->bounds);
- RectRgn (tPort->visRgn, &tBitMapPtr->bounds);
-
- SetPort (savedPort);
-
- /**
- ** Create the TELiteHandle requested by the calling function.
- **
- **/
-
- theTELite = (TELiteHandle) NewHandle (sizeof (TELiteRec));
- if (theTELite == nil) {
- AlertUser ("\pCan't allocate memory for our text edit lite", MemError ());
- DisposPtr ((Ptr) tBitMapPtr);
- DisposPtr ((Ptr) tPort);
- ReleaseResource ((Handle) lwinResource);
- return (nil);
- }
-
- (**theTELite).offScreenPort = tPort;
- (**theTELite).lineHeight = lineHeight;
- (**theTELite).fontAscent = tPortFontInfo.ascent;
- (**theTELite).maxLines = (*lwinResource)->numOfLines;
- (**theTELite).minWidth = (*lwinResource)->minWidth;
- (**theTELite).numOfLines = 0;
- (**theTELite).top = 0;
- (**theTELite).left = 0;
-
- ReleaseResource ((Handle) lwinResource);
- return (theTELite);
- }
-
-
- #pragma segment LogWindowSeg
- void DoLogWindowClick (WindowPtr theWindow, const EventRecord * theEvent)
- {
- short part, value;
- ControlHandle theControl;
- Point mousePos;
- WindowPtr savedPort;
- Rect teRect;
-
- GetPort (&savedPort);
- SetPort (theWindow);
-
- mousePos = theEvent->where;
- GlobalToLocal (&mousePos);
-
- GetTERect (theWindow, &teRect);
-
- if (PtInRect (mousePos, &teRect))
- {
- }
- else
- {
- part = FindControl (mousePos, theWindow, &theControl);
- switch (part) {
- case 0 : // invisible or inactive control was clicked
- break;
-
- case inThumb :
- value = GetCtlValue (theControl);
- part = TrackControl (theControl, mousePos, nil);
- if (part != 0) {
- value -= GetCtlValue (theControl);
-
- if (value != 0)
- TELiteScroll ((LogWindowPtr) theWindow, value);
- }
- break;
-
- case inButton:
- part = TrackControl (theControl, mousePos, nil);
- if (part != 0) {
- ClearLogWindow ((LogWindowPtr) theWindow);
- }
- break;
-
- case inCheckBox:
- part = TrackControl (theControl, mousePos, nil);
- if (part != 0) {
- ((LogWindowPtr) theWindow)->saveToDisk =
- value = (GetCtlValue (theControl)) ? false : true;
- SetCtlValue (theControl, value);
- if ((value != 0) && (((LogWindowPtr) theWindow)->logFileSpec == nil))
- if (FillFSSpec ((LogWindowPtr) theWindow) == false) {
- SetCtlValue (theControl, false);
- ((LogWindowPtr) theWindow)->saveToDisk = false;
- }
- }
- break;
-
- default :
- value = TrackControl (theControl, mousePos, gVActionProcUPP);
- }
- }
-
- SetPort (savedPort);
- }
-
-
- #pragma segment LogWindowSeg
- Boolean FillFSSpec (LogWindowPtr logWindow)
- {
- OSErr errCode;
- Rect nameRect;
- WindowPtr savedPort;
- DateTimeRec date;
- Str255 tStr;
- StandardFileReply theReply;
- CursHandle watch = GetCursor(watchCursor);
-
- if (watch != nil) SetCursor (*watch);
-
- GetTime (&date);
- sprintf ((char *) tStr,"%02d.%02d.%02d-%02d.%02d.%02d", date.month, date.day, date.year,
- date.hour, date.minute, date.second);
- c2pstr ((char *) tStr);
-
- StandardPutFile ("\pSave log to :", tStr, &theReply);
-
- if (theReply.sfGood) {
-
- if (theReply.sfReplacing) {
- errCode = FSpDelete(&theReply.sfFile);
- if (errCode != noErr) {
- AlertUser ("\pUnable to delete the file.", errCode);
- return (false);
- }
- }
-
- errCode = FSpCreate (&theReply.sfFile, 'ttxt', 'TEXT', theReply.sfScript);
- if (errCode != noErr) {
- AlertUser ("\pUnable to create the specified file.", errCode);
- return (false);
- }
-
- if (logWindow->logFileSpec == nil)
- logWindow->logFileSpec = (FSSpecHandle) NewHandle (sizeof (FSSpec));
-
- (**logWindow->logFileSpec) = theReply.sfFile;
-
- GetPort (&savedPort);
- SetPort ((WindowPtr) logWindow);
- nameRect = ((WindowPtr) logWindow)->portRect;
- nameRect.bottom = nameRect.top + kTopMargin - 3;
- InvalRect (&nameRect);
- SetPort (savedPort);
- } else {
- }
-
- SetCursor (&qd.arrow);
- return (theReply.sfGood);
- }
-
-
- #pragma segment LogWindowSeg
- pascal void VActionProc (ControlHandle theControl, short part)
- {
- short amount;
- LogWindowPtr logWindow;
- TELitePtr tTELite;
- Rect viewRect;
-
- if (part != 0) {
- logWindow = (LogWindowPtr) (*theControl)->contrlOwner;
- tTELite = *logWindow->fTELiteHandle;
-
- switch (part) {
- case inUpButton :
- case inDownButton :
- amount = 1;
- break;
- case inPageUp :
- case inPageDown :
- GetTERect ((WindowPtr) logWindow, &viewRect);
- amount = (viewRect.bottom - viewRect.top) / tTELite->lineHeight;
- break;
- }
- if ((part == inDownButton) || (part == inPageDown))
- amount = -amount;
-
- CommonAction (theControl, &amount);
-
- if (amount != 0)
- TELiteScroll (logWindow, amount);
- }
- }
-
-
- #pragma segment LogWindowSeg
- void CommonAction (ControlHandle theControl, short * amount)
- {
- short value, max;
-
- value = GetCtlValue (theControl);
- max = GetCtlMax (theControl);
- *amount = value - *amount;
- if (*amount < 0)
- *amount = 0;
- else if (*amount > max)
- *amount = max;
-
- SetCtlValue (theControl, *amount);
- *amount = value - *amount;
- }
-
-
- #pragma segment LogWindowSeg
- void DrawFromOffscreen (LogWindowPtr logWindow)
- {
- WindowPtr savedPort;
- BitMap tBitMap;
- TELiteHandle tTELite;
- Rect offScreenRect;
- Rect destRect;
-
- GetPort (&savedPort);
- SetPort ((WindowPtr) logWindow);
-
- tTELite = logWindow->fTELiteHandle;
- tBitMap = ((**tTELite).offScreenPort)->portBits;
-
- GetTERect ((WindowPtr) logWindow, &destRect);
- offScreenRect = tBitMap.bounds;
- offScreenRect.top = (**tTELite).top;
- offScreenRect.left = (**tTELite).left;
-
- if ((offScreenRect.bottom-offScreenRect.top) > (destRect.bottom-destRect.top))
- offScreenRect.bottom = offScreenRect.top + destRect.bottom-destRect.top;
- else
- destRect.bottom = destRect.top + offScreenRect.bottom-offScreenRect.top;
-
- if ((offScreenRect.right-offScreenRect.left) > (destRect.right-destRect.left))
- offScreenRect.right = offScreenRect.left + destRect.right-destRect.left;
- else
- destRect.right = destRect.left + offScreenRect.right-offScreenRect.left;
-
-
- CopyBits (&tBitMap, &((WindowPtr) logWindow)->portBits, &offScreenRect,
- &destRect, srcCopy, nil);
-
- SetPort (savedPort);
- }
-
-
- #pragma segment LogWindowSeg
- void DrawLogWindow (WindowPtr theWindow)
- {
- WindowPtr savedPort;
- Rect cntlRect = (**((LogWindowPtr) theWindow)->saveCheckBox).contrlRect;
- char cString[kStrBufferSize];
- char savedState;
- FSSpecHandle tFSSpecHandle;
-
- GetPort (&savedPort);
- SetPort (theWindow);
-
- EraseRect(&theWindow->portRect);
- UpdtControl (theWindow, theWindow->visRgn);
-
- ShowGrowIcon (theWindow);
-
- DrawFromOffscreen ((LogWindowPtr) theWindow);
-
- getindstring (cString, rLogWindowIndSTR, kSaveToDiskInd);
- MoveTo (cntlRect.right, cntlRect.bottom - 5);
-
- tFSSpecHandle = ((LogWindowPtr) theWindow)->logFileSpec;
- if (tFSSpecHandle != nil) {
- savedState = HGetState((Handle) tFSSpecHandle);
- HLock((Handle) tFSSpecHandle);
-
- (void) strncat (cString, (char *) (**tFSSpecHandle).name+1, (**tFSSpecHandle).name[0]);
-
- HSetState((Handle) tFSSpecHandle, savedState);
- }
-
- if (theWindow != FrontWindow())
- TextMode (grayishTextOr);
-
- drawstring (cString);
- TextMode (srcOr);
-
- MoveTo (0, kTopMargin-1); Line ((theWindow->portRect.right - theWindow->portRect.left), 0);
- MoveTo (0, kTopMargin-3); Line ((theWindow->portRect.right - theWindow->portRect.left), 0);
-
- SetPort (savedPort);
- }
-
-
- #pragma segment LogWindowSeg
- void DoLogWindowActivate (WindowPtr theWindow, Boolean becomingActive)
- {
- WindowPtr savedPort;
- Rect nameRect;
-
- GetPort (&savedPort);
- SetPort (theWindow);
-
- HiliteControl (((LogWindowPtr) theWindow)->clearLogButton, (becomingActive)?0:0xFF);
-
- if (becomingActive)
- ShowControl(((LogWindowPtr) theWindow)->vScroll);
- else
- HideControl(((LogWindowPtr) theWindow)->vScroll);
-
- ShowGrowIcon (theWindow);
-
- nameRect = (theWindow)->portRect;
- nameRect.bottom = nameRect.top + kTopMargin - 3;
- nameRect.left += (*(((LogWindowPtr) theWindow)->saveCheckBox))->contrlRect.right;
- InvalRect (&nameRect);
-
- SetPort (savedPort);
- }
-
-
- #pragma segment LogWindowSeg
- void DoLogWindowUpdate (WindowPtr theWindow)
- {
- BeginUpdate (theWindow);
- if ( ! EmptyRgn (theWindow->visRgn) )
- {
- DrawLogWindow (theWindow);
- }
- EndUpdate (theWindow);
- }
-
-
- #pragma segment LogWindowSeg
- void AdjustHeight (short * height, LogWindowPtr logWindow)
- {
- short lh = (**(logWindow)->fTELiteHandle).lineHeight;
-
- *height = ((*height - kTopMargin) / lh) * lh + kTextMargin + kTextMargin + kTopMargin;
- }
-
-
- #pragma segment LogWindowSeg
- void DoLogWindowGrow (WindowPtr theWindow, const EventRecord * theEvent)
- {
- long growResult;
- Rect growRect, screenRect;
- WindowPtr savedPort;
- TELitePtr theTELite;
- RgnHandle grayRgn = GetGrayRgn ();
-
- screenRect = (*grayRgn)->rgnBBox;
-
- theTELite = *((LogWindowPtr)theWindow)->fTELiteHandle;
-
- growRect = theTELite->offScreenPort->portBits.bounds;
- growRect.bottom += kTextMargin + kTextMargin + 1 + kTopMargin;
- growRect.right += kTextMargin + kTextMargin + 17;
-
- if ((growRect.bottom-growRect.top) > (screenRect.bottom-screenRect.top))
- growRect.bottom = growRect.top + screenRect.bottom-screenRect.top;
-
- if ((growRect.right-growRect.left) > (screenRect.right-screenRect.left))
- growRect.right = growRect.left + screenRect.right-screenRect.left;
-
- growRect.left = theTELite->minWidth;
- growRect.top = 5 * theTELite->lineHeight + kTextMargin + kTextMargin + kTopMargin; // allow to shrink window down to 5 lines
-
- growResult = GrowWindow (theWindow, theEvent->where, &growRect);
-
- if ( growResult != 0 ) {
- short height = HiWord(growResult);
- AdjustHeight (&height, (LogWindowPtr) theWindow);
- SizeWindow (theWindow, LoWord(growResult), height, true);
- AdjustScrollbars ((LogWindowPtr) theWindow, true);
-
- GetPort (&savedPort);
- SetPort (theWindow);
- InvalRect (&theWindow->portRect);
- SetPort (savedPort);
- }
- }
-
-
- #pragma segment LogWindowSeg
- void DoLogWindowZoom (WindowPtr theWindow, short zoomDirection)
- {
- WindowPtr savedPort;
- Rect zoomRect;
- TELitePtr theTELite;
- short height;
-
- GetPort (&savedPort);
- SetPort (theWindow);
-
- theTELite = *((LogWindowPtr)theWindow)->fTELiteHandle;
- zoomRect = theTELite->offScreenPort->portBits.bounds;
- zoomRect.bottom += kTextMargin + kTextMargin + kTopMargin;
- zoomRect.right += kTextMargin + kTextMargin + 16;
-
- ZoomWindowInCurrentDevice (theWindow, zoomRect.right - zoomRect.left,
- zoomRect.bottom - zoomRect.top, zoomDirection, theWindow == FrontWindow());
-
- zoomRect = theWindow->portRect;
- height = zoomRect.bottom - zoomRect.top;
- AdjustHeight (&height, (LogWindowPtr) theWindow);
- SizeWindow (theWindow, zoomRect.right - zoomRect.left, height, true);
- AdjustScrollbars ((LogWindowPtr) theWindow, true);
-
- InvalRect (&theWindow->portRect);
- SetPort (savedPort);
- }
-
-
- #pragma segment LogWindowSeg
- void ShowGrowIcon (WindowPtr theWindow)
- {
- RgnHandle savedClipRgn;
- Rect growIconRect;
- WindowPtr savedPort;
-
- GetPort (&savedPort);
- SetPort (theWindow);
- savedClipRgn = NewRgn ();
- GetClip (savedClipRgn);
- growIconRect = theWindow->portRect;
- growIconRect.top += kTopMargin;
- growIconRect.left = growIconRect.right - 15;
- ClipRect (&growIconRect);
- DrawGrowIcon(theWindow);
- SetClip (savedClipRgn);
- DisposeRgn (savedClipRgn);
- SetPort (savedPort);
- }
-
-
- #pragma segment LogWindowSeg
- void AppendLine (LogWindowPtr logWindow, const char * cStr)
- {
- FSSpec tFSSpec;
- OSErr errCode;
- short refNum;
- char endln = '\n';
- long count = strlen (cStr);
-
- tFSSpec = **logWindow->logFileSpec;
-
- errCode = FSpOpenDF (&tFSSpec, fsRdWrPerm, &refNum);
- if (errCode == noErr) {
- errCode = SetFPos (refNum, fsFromLEOF, 0);
- errCode = FSWrite (refNum, &count, cStr);
-
- count = 1;
- errCode = FSWrite (refNum, &count, &endln);
-
- errCode = FSClose (refNum);
- errCode = FlushVol (nil, tFSSpec.vRefNum);
- }
- else {
- logWindow->saveToDisk = false;
- SetCtlValue (logWindow->saveCheckBox, false);
- PutLine (logWindow, "### FSpOpenDF failed, OSErr = %d", errCode);
- DisposHandle ((Handle) logWindow->logFileSpec);
- logWindow->logFileSpec = nil;
- }
- }
-
-
- #pragma segment LogWindowSeg
- void VPutLine (LogWindowPtr logWindow, const char * format, va_list ap)
- {
- char cStr[kStrBufferSize];
- long len;
-
- if (logWindow != nil) {
- len = vsprintf ((char *) cStr, format, ap);
-
- PutTextToLogWindow (logWindow, cStr);
- }
- }
-
-
- #pragma segment LogWindowSeg
- void PutLine (LogWindowPtr logWindow, const char * format, ...)
- {
- va_list ap;
- char cStr[kStrBufferSize];
- long len;
-
- if (logWindow != nil) {
- va_start (ap, format);
- len = vsprintf ((char *) cStr, format, ap);
- va_end (ap);
-
- PutTextToLogWindow (logWindow, cStr);
- }
- }
-
-
- #pragma segment LogWindowSeg
- void PutTextToLogWindow (LogWindowPtr logWindow, const char * cStr)
- {
- WindowPtr savedPort;
- TELiteHandle tTELite;
- short max, value;
-
- tTELite = logWindow->fTELiteHandle;
- GetPort (&savedPort);
- SetPort ((**tTELite).offScreenPort);
-
- if ((**tTELite).numOfLines < (**tTELite).maxLines) {
- MoveTo (0, (**tTELite).numOfLines * (**tTELite).lineHeight + (**tTELite).fontAscent);
- ++(**tTELite).numOfLines;
- }
- else {
- RgnHandle updateRgn = NewRgn ();
- ScrollRect (&((**tTELite).offScreenPort)->portRect, 0, -(**tTELite).lineHeight, updateRgn);
- MoveTo (0, ((**tTELite).maxLines-1) * (**tTELite).lineHeight + (**tTELite).fontAscent);
- DisposeRgn (updateRgn);
- }
-
- drawstring (cStr);
-
- AdjustScrollbars (logWindow, false);
-
- max = GetCtlMax (logWindow->vScroll);
- value = GetCtlValue (logWindow->vScroll);
- if ((max != 0) && (value < max)) {
- SetCtlValue (logWindow->vScroll, max);
- (**tTELite).top = max * (**tTELite).lineHeight;
- }
-
- DrawFromOffscreen (logWindow);
-
- SetPort (savedPort);
-
- if (logWindow->saveToDisk)
- AppendLine (logWindow, cStr);
- }
-
-
- #pragma segment LogWindowSeg
- void PutCLine (LogWindowPtr logWindow, long color, const char * format, ...)
- {
- va_list ap;
- char cStr[kStrBufferSize];
- long len;
- WindowPtr savedPort;
- TELiteHandle tTELite;
- short max, value;
-
- if (logWindow != nil) {
- va_start (ap, format);
- len = vsprintf ((char *) cStr, format, ap);
- va_end (ap);
-
- tTELite = logWindow->fTELiteHandle;
- GetPort (&savedPort);
- SetPort ((**tTELite).offScreenPort);
- ForeColor (color);
-
- if ((**tTELite).numOfLines < (**tTELite).maxLines) {
- MoveTo (0, (**tTELite).numOfLines * (**tTELite).lineHeight + (**tTELite).fontAscent);
- ++(**tTELite).numOfLines;
- }
- else {
- RgnHandle updateRgn = NewRgn ();
- ScrollRect (&((**tTELite).offScreenPort)->portRect, 0, -(**tTELite).lineHeight, updateRgn);
- MoveTo (0, ((**tTELite).maxLines-1) * (**tTELite).lineHeight + (**tTELite).fontAscent);
- DisposeRgn (updateRgn);
- }
-
- drawstring (cStr);
-
- AdjustScrollbars (logWindow, false);
-
- max = GetCtlMax (logWindow->vScroll);
- value = GetCtlValue (logWindow->vScroll);
- if ((max != 0) && (value < max)) {
- SetCtlValue (logWindow->vScroll, max);
- (**tTELite).top = max * (**tTELite).lineHeight;
- }
-
- DrawFromOffscreen (logWindow);
-
- ForeColor (blackColor);
- SetPort (savedPort);
-
- if (logWindow->saveToDisk)
- AppendLine (logWindow, cStr);
- }
- }
-
-
- #pragma segment LogWindowSeg
- void TELiteScroll (LogWindowPtr logWindow, short amount)
- {
- TELiteHandle tTELite;
-
- tTELite = logWindow->fTELiteHandle;
- (**tTELite).top -= amount * (**tTELite).lineHeight;
-
- DrawFromOffscreen (logWindow);
- }
-
-
- #pragma segment LogWindowSeg
- void AdjustScrollbars (LogWindowPtr logWindow, Boolean needsResize)
- {
- #define kControlInvisible 0
- #define kControlVisible 0xFF
-
- // (*logWindow->vScroll)->contrlVis = kControlInvisible;
-
- if ( needsResize )
- AdjustScrollSizes (logWindow);
- AdjustScrollValues (logWindow, needsResize);
-
- // (*logWindow->vScroll)->contrlVis = kControlVisible;
- }
-
-
- #pragma segment LogWindowSeg
- void AdjustScrollSizes (LogWindowPtr logWindow)
- {
- MoveControl(logWindow->vScroll, ((WindowPtr)logWindow)->portRect.right - 15, kTopMargin-1);
- SizeControl(logWindow->vScroll, 16, (((WindowPtr)logWindow)->portRect.bottom -
- ((WindowPtr)logWindow)->portRect.top) - 13 - kTopMargin);
- }
-
-
- #pragma segment LogWindowSeg
- void GetTERect (WindowPtr theWindow, Rect * theRect)
- {
- *theRect = theWindow->portRect;
- InsetRect (theRect, kTextMargin, kTextMargin);
- theRect->top += kTopMargin;
- theRect->right -= 15;
- }
-
-
- #pragma segment LogWindowSeg
- void AdjustScrollValues (LogWindowPtr logWindow, Boolean canRedraw)
- {
- AdjustHV(true, logWindow->vScroll, logWindow->fTELiteHandle, canRedraw);
- }
-
-
- #pragma segment LogWindowSeg
- void AdjustHV (Boolean isVert, ControlHandle control, TELiteHandle theTELite, Boolean canRedraw)
- {
- #pragma unused (isVert)
-
- short value, max;
- short oldValue, oldMax;
- TELitePtr te;
- Rect viewRect;
-
- GetTERect ((*control)->contrlOwner, &viewRect);
-
- oldValue = GetCtlValue (control);
- oldMax = GetCtlMax (control);
- te = *theTELite;
-
- max = te->numOfLines - ((viewRect.bottom - viewRect.top) /
- te->lineHeight);
-
- if ( max <= 0 ) {
- max = 0;
- te->top = 0;
- } else { // max > 0
- if (te->top != max * te->lineHeight)
- te->top = max * te->lineHeight;
- }
-
- SetCtlMax (control, max);
-
- te = *theTELite;
- value = te->top / te->lineHeight;
-
- if ( value < 0 ) value = 0;
- else if ( value > max ) value = max;
-
- SetCtlValue(control, value);
-
- if ( (*control)->contrlVis && (canRedraw || (max != oldMax) || (value != oldValue)) )
- ShowControl(control);
- }
-
-
- #pragma segment LogWindowSeg
- void ClearLogWindow (LogWindowPtr logWindow)
- {
- WindowPtr savedPort;
- Rect tRect;
- TELiteHandle teHand = logWindow->fTELiteHandle;
-
- SetCtlValue (logWindow->vScroll, 0);
- SetCtlMax (logWindow->vScroll, 0);
-
- (*teHand)->top = (*teHand)->left = (*teHand)->numOfLines = 0;
-
- GetPort (&savedPort);
- SetPort ((*teHand)->offScreenPort);
- EraseRect (&(*teHand)->offScreenPort->portRect);
-
- SetPort ((WindowPtr) logWindow);
- GetTERect ((WindowPtr) logWindow, &tRect);
- InvalRect (&tRect);
- SetPort (savedPort);
- }
-
-
-